﻿using System;
using System.Collections;
using UnityEngine;

// Token: 0x02000406 RID: 1030
public static class Transform_Utility
{
	// Token: 0x060019A3 RID: 6563 RVA: 0x000A53B8 File Offset: 0x000A35B8
	public static Transform FindTransform(Transform transform, string name)
	{
		if (transform == null)
		{
			return null;
		}
		if (transform.name == name)
		{
			return transform;
		}
		IEnumerator enumerator = transform.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				object obj = enumerator.Current;
				Transform transform2 = (Transform)obj;
				Transform transform3 = Transform_Utility.FindTransform(transform2, name);
				if (transform3 != null)
				{
					return transform3;
				}
			}
		}
		finally
		{
			IDisposable disposable;
			if ((disposable = (enumerator as IDisposable)) != null)
			{
				disposable.Dispose();
			}
		}
		return null;
	}

	// Token: 0x060019A4 RID: 6564 RVA: 0x000A5454 File Offset: 0x000A3654
	public static Transform FindTransform_Partial(Transform transform, string name)
	{
		if (transform.name.IndexOf(name) != -1)
		{
			return transform;
		}
		IEnumerator enumerator = transform.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				object obj = enumerator.Current;
				Transform transform2 = (Transform)obj;
				Transform transform3 = Transform_Utility.FindTransform_Partial(transform2, name);
				if (transform3 != null)
				{
					return transform3;
				}
			}
		}
		finally
		{
			IDisposable disposable;
			if ((disposable = (enumerator as IDisposable)) != null)
			{
				disposable.Dispose();
			}
		}
		return null;
	}

	// Token: 0x060019A5 RID: 6565 RVA: 0x000A54E4 File Offset: 0x000A36E4
	public static string GetRelativePath(Transform root, Transform search)
	{
		IEnumerator enumerator = root.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				object obj = enumerator.Current;
				Transform check = (Transform)obj;
				string relativePath_Sub = Transform_Utility.GetRelativePath_Sub(check, search, string.Empty);
				if (relativePath_Sub != null)
				{
					return relativePath_Sub;
				}
			}
		}
		finally
		{
			IDisposable disposable;
			if ((disposable = (enumerator as IDisposable)) != null)
			{
				disposable.Dispose();
			}
		}
		return string.Empty;
	}

	// Token: 0x060019A6 RID: 6566 RVA: 0x000A5560 File Offset: 0x000A3760
	private static string GetRelativePath_Sub(Transform check, Transform search, string str)
	{
		if (str.Length > 0)
		{
			str += "/";
		}
		if (check == search)
		{
			str += search.name;
			return str;
		}
		str += check.name;
		IEnumerator enumerator = check.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				object obj = enumerator.Current;
				Transform check2 = (Transform)obj;
				string relativePath_Sub = Transform_Utility.GetRelativePath_Sub(check2, search, str);
				if (relativePath_Sub != null)
				{
					return relativePath_Sub;
				}
			}
		}
		finally
		{
			IDisposable disposable;
			if ((disposable = (enumerator as IDisposable)) != null)
			{
				disposable.Dispose();
			}
		}
		return null;
	}

	// Token: 0x060019A7 RID: 6567 RVA: 0x000A5618 File Offset: 0x000A3818
	public static Type FindComponent<Type>(string name) where Type : Component
	{
		GameObject gameObject = GameObject.Find(name);
		if (gameObject != null)
		{
			return gameObject.GetComponent<Type>();
		}
		return (Type)((object)null);
	}

	// Token: 0x060019A8 RID: 6568 RVA: 0x000A5648 File Offset: 0x000A3848
	public static Type FindComponent<Type>(GameObject obj, string name) where Type : Component
	{
		Transform transform = Transform_Utility.FindTransform(obj.transform, name);
		GameObject gameObject = (!(transform != null)) ? null : transform.gameObject;
		if (gameObject)
		{
			return gameObject.GetComponent<Type>();
		}
		return (Type)((object)null);
	}

	// Token: 0x060019A9 RID: 6569 RVA: 0x000A5694 File Offset: 0x000A3894
	public static Type GetComponent<Type>(GameObject obj) where Type : Component
	{
		return obj.GetComponent<Type>();
	}
}
